//
//  ViewController.m
//  YCAlertController
//
//  Created by Yochia on 2017/1/11.
//  Copyright © 2017年 Team Brutal. All rights reserved.
//

#import "ViewController.h"
#import "YCPopupController.h"

@interface ViewController ()

@property (nonatomic, strong) YCPopupController * popupController;

@end

NSString *const message = @"提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容提醒内容";
NSString *const title = @"提醒";

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.popupController = [[YCPopupController alloc] init];

    UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake((self.view.frame.size.width - 150) / 2, 100, 150, 20);
    [btn setTitle:@"YCAlertController" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(showAlert) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

}

- (void)showAlert {
    __weak typeof(self) weakSelf = self;
    [self.popupController setPopupViewWithAlertHandler:^(YCAlertView *alertView) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        
        [alertView removeAllAction];
        [alertView removeAllCustomView];
        
        alertView.title = title;
        alertView.message = message;
        alertView.dismissedWhenClicked = NO;
        
        UITextField * field = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
        field.placeholder = @"UITextField";
        field.borderStyle = UITextBorderStyleRoundedRect;
        [alertView addCustomView:field];
        
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
        view.backgroundColor = [UIColor grayColor];
        [alertView addCustomView:view];
        
        UILabel * label = [UILabel new];
        label.text = @"UILabel";
        [label sizeToFit];
        [alertView addCustomView:label];
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
        [button setTitle:@"UIButton" forState:UIControlStateNormal];
        [button sizeToFit];
        [alertView addCustomView:button];
    
        UISwitch * switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
        [alertView addCustomView:switchBtn];
    
        [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
            textField.placeholder = @"这是一个Alert自生成的TextField";
        }];
    
        [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
            textField.placeholder = @"这是一个Alert自生成的TextField";
        }];
        
        [alertView addAction:[YCAlertAction actionWithTitle:@"删除标题" style:YCAlertActionStyleDestructive handler:^(YCAlertAction * action) {
            [strongSelf changeTitle];
        }]];
        [alertView addAction:[YCAlertAction actionWithTitle:@"删除内容文本" style:YCAlertActionStyleDefault handler:^(YCAlertAction *action) {
            [strongSelf changeMessage];
        }]];
        [alertView addAction:[YCAlertAction actionWithTitle:@"删除自定义View" style:YCAlertActionStyleCancel handler:^(YCAlertAction *action) {
            [strongSelf changeCustomViews];
        }]];
        [alertView addAction:[YCAlertAction actionWithTitle:@"显示HUD" style:YCAlertActionStyleDefault handler:^(YCAlertAction *action) {
            [strongSelf showHUD];
        }]];

        [alertView addAction:[YCAlertAction actionWithTitle:@"取消显示" style:YCAlertActionStyleDefault handler:^(YCAlertAction *action) {
            [strongSelf.popupController dismiss:YES];
        }]];
    }];

    [self.popupController showInViewController:self animated:YES];
}

- (void)showHUD {
    [self.popupController setPopupViewWithHUDHandler:^(YCHUDView *hudView) {
        hudView.title = @"提醒";
        hudView.message = @"提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒提醒";
        hudView.await = YES;
    }];
    [self.popupController showInViewController:self animated:YES];
}

- (void)changeTitle {
    [self.popupController setPopupViewWithAlertHandler:^(YCAlertView *alertView) {
        alertView.title = @"";
    }];
}

- (void)changeMessage {
    [self.popupController setPopupViewWithAlertHandler:^(YCAlertView *alertView) {
        alertView.message = @"";
    }];
}

- (void)changeCustomViews {
    [self.popupController setPopupViewWithAlertHandler:^(YCAlertView *alertView) {
        [alertView removeAllCustomView];
    }];
}

@end
